/**
* @author maze | guavestudios.com
* @license MIT License see LICENSE.TXT
* @version 0.1
*/

package com.guavestudios.fcon.plugins {
	import flash.utils.Dictionary;
	import com.guavestudios.fcon.api.IControlableConsole;

	public class PluginManager {
		
		private var console:IControlableConsole;
		private var plugins:Dictionary;
		
		public function PluginManager() {
			plugins=new Dictionary();
		}
		public function setConsole(c:IControlableConsole):void
		{
			console=c;
		}
		/**
		* Register a new plugin
		* @param	c	plugin
		*/
		public function addPlugin(c:IConsolePlugin):void
		{
			c.initPlugin(console);
			plugins[c.Name]=c;
		}
		/**
		* Remove a plugin
		* @param	s	unique name
		*/
		public function removePlugin(s:String):void
		{
			IConsolePlugin(plugins[s]).unloadPlugin();
			plugins[s]=undefined;
		}
		/**
		* Get a plugin by unique name
		* @param	s	unique plugin name
		* @return	the plugin or null if the plugin was not found
		*/
		public function getPlugin(s:String):IConsolePlugin
		{
			return plugins[s];
		}
		/**
		* Check if a plugin is registerd
		* @param	s	unique name of the plugin
		* @return	true if the plugin is available false if not
		*/
		public function hasPlugin(s:String):Boolean
		{
			return plugins[s]!=undefined;
		}
	}
	
}
